/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.rw.table.formatter;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import javax.swing.SwingConstants;

/**
 *
 * @author Rene Tapia
 */
public class DateCellFormatter implements ICellFormatter {

    public static String PATTERN = "dd/MM/yyyy, HH:mm:ss";
    //
    private DateFormat df;

    public DateCellFormatter() {
        this(PATTERN);
    }

    public DateCellFormatter(String pattern) {
        df = new SimpleDateFormat(pattern);
    }

    @Override
    public String format(Object value) {
        Date date = (Date) value;
        return df.format(date);
    }

    @Override
    public Object parse(String strValue) throws ParseException {
        return df.parse(strValue);
    }

    @Override
    public int getAlign() {
        return SwingConstants.LEFT;
    }
}
